//
//  MyCollectionCell.m
//  14---练习collectionview
//
//  Created by 冀永金 on 16/8/2.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "MyCollectionCell.h"
#import "CollectionViewCell.h"
@interface MyCollectionCell ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong) UICollectionView *collection;
@end
@implementation MyCollectionCell
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self config];
    }
    return self;
}
- (void)config {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.sectionInset = UIEdgeInsetsMake(40, 10, 10, 10);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.itemSize = CGSizeMake((self.contentView.frame.size.width - 30) / 2, (self.contentView.frame.size.width - 30) / 4);
    layout.minimumInteritemSpacing = 10;
    layout.minimumLineSpacing = 10;
    self.collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, 300) collectionViewLayout:layout];
    [self.contentView addSubview:_collection];
    _collection.delegate = self;
    _collection.dataSource = self;
    _collection.pagingEnabled = YES;
    _collection.backgroundColor = [UIColor whiteColor];
    [_collection registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"pool"];
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(5, 14, 80, 30)];
    [self addSubview:label];
    label.text = @"分类";
    
    UICollectionViewFlowLayout *layout1 = [[UICollectionViewFlowLayout alloc]init];
    layout1.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout1.minimumLineSpacing = 5;
    layout1.minimumInteritemSpacing = 5;
    layout1.itemSize = CGSizeMake((self.contentView.frame.size.width - 10) / 3, (self.contentView.frame.size.width - 10) / 3);
    UICollectionView *collection1 = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 330, self.contentView.frame.size.width, 1000) collectionViewLayout:layout1];
    [self addSubview:collection1];
    collection1.backgroundColor = [UIColor yellowColor];
    collection1.delegate =self;
    collection1.dataSource = self;
    
    [collection1 registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"pool1"];
    
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (collectionView == _collection ) {
        return 6;
    }
    else {
        return 10;
    }
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath  {
    if (collectionView == _collection) {
        
        UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor grayColor];
        return cell;
    }
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool1" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor blueColor];
    return cell;
}
@end
